package cn.bitkit.tools.common;

import java.util.Comparator;
import java.util.List;
import java.util.function.Function;

/**
 * 搜索简易工具类
 */
public class SearchUtil {

    public static <T> T match(List<T> list, String target, Function<T, String> getValue){
        List<T> sortedList = list.stream()
                .sorted(Comparator.comparingDouble(e -> SimilarityUtil.calculateSimilarity(getValue.apply(e), target)))
                .toList();
        return sortedList.getLast();
    }

    public static String match(List<String> list, String target){
        List<String> sortedList = list.stream()
                .sorted(Comparator.comparingDouble(e -> SimilarityUtil.calculateSimilarity(e, target)))
                .toList();
        return sortedList.getLast();
    }

}
